import { App } from 'antd';
import { useCallback } from 'react';

export const useCatch = () => {
  const { message } = App.useApp();
  return useCallback(
    <T,>(fn: () => T) => {
      try {
        return fn();
      } catch (e) {
        message.error(e.message);
        throw new Error(e.message);
      }
    },
    [message],
  );
};
